<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>文章中心--->修改</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${ctxPath}/static/manage/css/x-admin.css" media="all">
    <script src="${ctxPath}/static/manage/js/jquery.js"></script>
    <script src="${ctxPath}/static/manage/layui/layui.js"></script>
    <script src="${ctxPath}/static/manage/js/x-layui.js" charset="utf-8"></script>
</head>
<body>
    <form class="layui-form" id="formUpdate">
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="x-red">*</span>电脑名称</label>
        <div class="layui-input-inline">
            <input type="text" id="name" name="name" class="layui-input" value="${computerMethod.name}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="x-red">*</span>电脑类型</label>
        <div class="layui-input-inline typeSelect">
            <input id="typeName" type="hidden" value="${computerMethod.mid}">
            <select name="mid" id="mid" lay-filter="typeComputer">
                <option value="">请选择</option>
            </select>
        </div>
    </div>
    <button class="layui-btn" type="button"  lay-filter="update" lay-submit="">修改</button>
    <input  type="hidden" id="id" name="id" value="${computerMethod.id}">

</form>
</body>

    <script type="text/javascript">

        layui.use(['form', 'layedit', 'layer'], function(){
            var $ = layui.$, form = layui.form, layedit = layui.layedit;

            //回显类型信息
            $(function () {
                var typeName = $("#typeName").val();
                $.ajax({
                    type: 'post',
                    url: '/manage/computerMethod/ComputerMethodType',

                    success:function(res){
                        if (res.length > 0) {
                            for (var i = 0; i < res.length; i++) {

                                if (typeName == res[i].id) {
                                    $("#mid").append("<option value='" + res[i].id+ "' selected='selected'>" + res[i].type+ "</option>");
                                    form.render();
                                } else {
                                    $("#mid").append("<option value='" + res[i].id+ "'>" + res[i].type + "</option>");
                                    form.render();
                                }
                            }
                        }
                    }
                });
            })

            // 监听提交
            form.on('submit(update)', function(){

                if($("#mid").val()=="" || $("#mid").val().length<0){
                    alert("电脑类型没有选择");
                    return false;
                }
                if($("#name").val()=="" || $("#name").val().length<0){
                    alert("电脑名称不能为空");
                    return false;
                }

                $.ajax({
                    url : '/manage/computerMethod/computerMethodUpdate',
                    type:'post',
                    data:$("#formUpdate").serialize(),
                    success:function(result){
                        alert(result);
                        window.parent.location.reload();
                    },
                    error:function(result){
                        alert("失败？请及时告知开发人员"+result);
                        window.parent.location.reload();
                    }
                });
            });

        });

    </script>
</html>